<?php

use yii\db\Migration;

class m170519_012520_create_customer_coupons_log extends Migration
{
    private function createDbs(){
        $dbs = [];
        $dbs_info =\Yii::$app->params['db'];
        foreach($dbs_info as $k=>$v){
            $dbs[$k] = \Yii::createObject($v);
        }
        return $dbs;
    }


    // Use safeUp/safeDown to run migration code within a transaction
    public function safeUp()
    {
        $dbs = $this->createDbs();
        foreach ($dbs as $v) {
            $this->db = $v;
            $this->createTable('{{%customer_coupons_log}}',[
                'id' => $this->primaryKey()->notNull().' COMMENT \'自增id\'',
                'customer_coupons_id' => $this->integer()->defaultValue(0).' COMMENT \'会员领取优惠券 id\'',
                'coupon_id' => $this->integer()->defaultValue(0).' COMMENT \'优惠券 id\'',
                'customer_id' => $this->integer()->defaultValue(0).' COMMENT \'会员id\'',
                'coupons_code_id' => $this->integer()->defaultValue(0).' COMMENT \'券码id\'',
                'invalid_time' => $this->integer()->defaultValue(0) .' COMMENT \'失效时间\'',
                'delay_invalid_time' => $this->integer()->defaultValue(0) .' COMMENT \'推迟后失效时间\'',
                'user_id' => $this->integer()->defaultValue(0) .' COMMENT \'操作人id\'',
                'create_at' => $this->integer()->defaultValue(0) .' COMMENT \'添加时间\''
            ]);
        }
    }

    public function safeDown()
    {
        $dbs = $this->createDbs();
        foreach($dbs as $v){
            $this->db = $v;
            $this->dropTable('{{%customer_coupons_log}}');
        }
    }
}
